#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

map<char, double> mp;
void init() {
  mp['C'] = 12.01;
  mp['H'] = 1.008;
  mp['O'] = 16.0;
  mp['N'] = 14.01;
}
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int l = 0;
  double res = 0;
  while (l < n) {
    int h = l + 1;
    int cnt = 0;
    while (h < n && isdigit(s[h])) {
      cnt = cnt * 10 + s[h] - '0';
      h++;
    }
    cnt = max(cnt, 1);
    res += mp[s[l]] * cnt;
    l = h;
  }
  cout << fixed << setprecision(3) << res << endl;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}